Mac下使用点云工具包PCL,按照官方说明可采用homebrew安装:
brew install pcl
但是会在vtk这个依赖工具上存在一些问题。
先安装好vtk (8.1.2),可采用homebrew:
brew install vtk
采用source源码编译安装:
git clone git@github.com:PointCloudLibrary/pcl.git
source pcl
mkdir build && cd build
cmake ..
make ## 好慢。。
sudo make install
PS: pcl官方还给出采用MacPorts的安装方式,测试之后发现有一些问题没配置成。。。所以卸载删除Macports,按照以上方式调通。
测试:
iterative_closest_point.cpp
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
int main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out (new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the CloudIn data
cloud_in->width = 5;
cloud_in->height = 1;
cloud_in->is_dense = false;
cloud_in->points.resize (cloud_in->width * cloud_in->height);
for (size_t i = 0; i < cloud_in->points.size (); ++i)
{
cloud_in->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud_in->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud_in->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
}
std::cout << "Saved " << cloud_in->points.size () << " data points to input:"
<< std::endl;
for (size_t i = 0; i < cloud_in->points.size (); ++i) std::cout << " " <<
cloud_in->points[i].x << " " << cloud_in->points[i].y << " " <<
cloud_in->points[i].z << std::endl;
*cloud_out = *cloud_in;
std::cout << "size:" << cloud_out->points.size() << std::endl;
for (size_t i = 0; i < cloud_in->points.size (); ++i)
cloud_out->points[i].x = cloud_in->points[i].x + 0.7f;
std::cout << "Transformed " << cloud_in->points.size () << " data points:"
<< std::endl;
for (size_t i = 0; i < cloud_out->points.size (); ++i)
std::cout << " " << cloud_out->points[i].x << " " <<
cloud_out->points[i].y << " " << cloud_out->points[i].z << std::endl;
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
icp.setInputSource(cloud_in);
icp.setInputTarget(cloud_out);
pcl::PointCloud<pcl::PointXYZ> Final;
icp.align(Final);
std::cout << "has converged:" << icp.hasConverged() << " score: " <<
icp.getFitnessScore() << std::endl;
std::cout << icp.getFinalTransformation() << std::endl;
return (0);
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(iterative_closest_point)
find_package(PCL 1.9 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (iterative_closest_point iterative_closest_point.cpp)
target_link_libraries (iterative_closest_point ${PCL_LIBRARIES})
test:
cd demo
mkdir build && cd build
cmake ..
make
PS:可以根据自己project的需要来调用pcl相应的函数,特别是其中的3DSC以及FPFH。 可参考源码中example/features/
下的几个demo。
亦可采用fast global registration提供的方法,将features写入到文件:
// Assume a point cloud with normal is given as
// pcl::PointCloud<pcl::PointNormal>::Ptr object
pcl::FPFHEstimationOMP<pcl::PointNormal, pcl::PointNormal, pcl::FPFHSignature33> fest;
pcl::PointCloud<pcl::FPFHSignature33>::Ptr object_features(new pcl::PointCloud<pcl::FPFHSignature33>());
fest.setRadiusSearch(feature_radius_);
fest.setInputCloud(object);
fest.setInputNormals(object);
fest.compute(*object_features);
FILE* fid = fopen("features.bin", "wb");
int nV = object->size(), nDim = 33;
fwrite(&nV, sizeof(int), 1, fid);
fwrite(&nDim, sizeof(int), 1, fid);
for (int v = 0; v < nV; v++) {
const pcl::PointNormal &pt = object->points[v];
float xyz[3] = {pt.x, pt.y, pt.z};
fwrite(xyz, sizeof(float), 3, fid);
const pcl::FPFHSignature33 &feature = object_features->points[v];
fwrite(feature.histogram, sizeof(float), 33, fid);
}
fclose(fid);